/*

DATE: June 18 2018

PROJECT: Police killings and mental health of black Americans, replication archive

PURPOSE: This file uses source data from the BRFSS to create individual dataset with focus on mental health outcomes. 

Specifically, will create three datasets:
(1) Full BRFSS sample
(2) BRFSS black sample
(3) BRFSS white sample

Our goal is to create a dataset of individuals interviewed after 2013, so we start with the 2012 BRFSS (which has a small number of participants - less than 0.75% - interviewed in early 2013).
Not including the 2012 BRFSS does not change our findings at all. In addition, we note that the 2015 BRFSS includes some individuals surveyed in early
2016. At the time of analysis and project development, the 2016 BRFSS was not released. We leave it to the reader to replicate and extend
with both more recent MPV and BRFSS data. 

To improve computational speed, we will use (2) and (3) in the bulk of analyses. Individuals with faster machines can use dataset
(1), being sure to include participant race in the regression and descriptive statistic "if" statements throughout.

*/


***CREATE (1)***

*FILEPATHS (User to delineate their own [FILE PATH] here!)
global source "[FILE PATH]/Source Datasets and Do Files/"
global working "[FILE PATH]/Working Datasets/"

*(A) Import data from SASXPT format into stata (imported files are not included in the working folder)
forvalues x = 2012/2015 {
	import sasxport "$source/LLCP`x'.XPT", clear
	keep _state imonth iday iyear idate _ageg5yr educa income2 sex _racegr genhlth menthlth physhlth poorhlth ///
	_rfsmok3 drnk3ge5 exerany2 _llcpwt _psu
	save "$source/brfss_police_`x'.dta", replace
	}

*(B) Append Datasets
clear
use "$source/brfss_police_2012.dta"

forvalues x = 2013/2015 {
	append using "$source/brfss_police_`x'.dta"
	}
	
replace _racegr2 = _racegr3 if _racegr2==.
drop _racegr3

*(C) Clean and recode variables
*This is the main outcome
recode menthlth  (77 = .) (88=0) (99 = .)

/*We do not use these in our published analysis, but leave them here for the interested reader
recode poorhlth physhlth (77 = .) (88=0) (99 = .)
recode genhlth (6/9 = .)
*/

recode educa (1/3 = 0) (4 = 1) (5 = 2) (6 = 3) (9 = .)
label define ed 0 "Less HS" 1 "HS" 2 "Some College" 3 "College"
label values educa ed

label define race 1 "White" 2 "Black" 3 "Other" 4 "Multi" 5 "Hispanic"
label values _racegr race

recode drnk3g (77 = .) (88=0) (99 = .)

*Date
destring imonth iday iyear, force replace
drop if iyear<2013
gen date = mdy(imonth, iday, iyear)
gen int_date = date
rename _state stfip
gen id = _n

save "$working/brfss_working_full_June182018.dta", replace
clear

***CREATE (2)***
use "$working/brfss_working_full_June182018.dta", clear

keep if _race==2
drop id
gen id = _n

save "$working/brfss_black_sample_June182018.dta", replace

***CREATE (3)***
use "$working/brfss_working_full_June182018.dta", clear

drop id
gen id = _n
keep if _race==1

save"$working/brfss_white_sample_June182018.dta", replace

